package br.ufms.cpcx.pitaco.activity;

import jim.h.common.android.zxinglib.integrator.IntentIntegrator;
import jim.h.common.android.zxinglib.integrator.IntentResult;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;
import br.ufms.cpcx.pitaco.R;
import br.ufms.cpcx.pitaco.model.Combo;
import br.ufms.cpcx.pitaco.model.Parametros;
import br.ufms.cpcx.pitaco.util.ComboRest;

public class MainActivity extends Activity {
	private Handler handler = new Handler();
	private TextView txtScanResult;
	private Button btler;
	private String aux, url;
	int valor;

	public MainActivity() {
		super();
		// TODO Auto-generated constructor stub
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		txtScanResult = (TextView) findViewById(R.id.resul);
		btler = (Button) findViewById(R.id.btqrcode);
		// TextView txt = (TextView) findViewById(R.id.texto);
		// Typeface font = Typeface.createFromAsset(getAssets(), "fely.ttf");
		// txt.setTypeface(font);
	}

	public void qrcode(View v) throws Exception {
		// IntentIntegrator.initiateScan(MainActivity.this, R.layout.capture,
		 IntentIntegrator.initiateScan(MainActivity.this,R.layout.capture,R.id.viewfinder_view, R.id.preview_view, true);
		

	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		switch (requestCode) {
		case IntentIntegrator.REQUEST_CODE:
			IntentResult scanResult = IntentIntegrator.parseActivityResult(
					requestCode, resultCode, data);
			if (scanResult == null) {
				return;
			}
			final String result = scanResult.getContents();
			if (result != null) {
				handler.post(new Runnable() {
					@Override
					public void run() {
						// txtScanResult.setText(result);
						Intent intent = new Intent(MainActivity.this,Tela.class);
						Bundle parametros = new Bundle();
						parametros.putString("url", result);
						intent.putExtras(parametros);
						startActivity(intent);
						finish();
					}
				});
			}
			break;
		default:
		}
	}	
}
